/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.manager;

import java.util.ArrayList;
import java.util.Collection;
import ru.jSkyRoom.CompositeMod;
import ru.jSkyRoom.bridge.ModBridge;
import ru.jSkyRoom.interfaces.JSkyMod;
import skyproc.Mod;
import skyproc.ModListing;
import skyproc.SPGlobal;

/**
 *
 * @author Rakev
 */
public class ModManager {

    private static ModManager instance = new ModManager();

    public static ModManager getInstance() {
        return instance;
    }

    private ModManager() {
    }

    public String getPathToData() {
        return SPGlobal.pathToData;
    }

    public void setPathToData(String path) {
        SPGlobal.pathToData = path;
    }

    public void setActiveMod(JSkyMod mod) {
        if (mod instanceof ModBridge) {
            ModBridge modBridge = (ModBridge) mod;
            SPGlobal.setGlobalPatch(modBridge.getRawObject());
        } else {
            throw new IllegalArgumentException("Supported only bridge.");
        }
    }

    public JSkyMod getActiveMod() {
        return new ModBridge(SPGlobal.getGlobalPatch());
    }

    public ModImporter getModImporter() {
        return ModImporter.getInstance();
    }

    public ModExporter getModExporter() {
        return ModExporter.getInstance();
    }

    public JSkyMod getModsWithoutActiveComposite() {
        return new CompositeMod(getModsWithoutActive());
    }

    public Collection<JSkyMod> getModsWithoutActive() {
        Collection<JSkyMod> importedMods = new ArrayList();
        for (Mod mod : SPGlobal.getDB()) {
            importedMods.add(new ModBridge(mod));
        }
        return importedMods;
    }

    public JSkyMod getAllModsComposite() {
        return new CompositeMod(getAllMods());
    }

    public Collection<JSkyMod> getAllMods() {
        Collection<JSkyMod> importedMods = new ArrayList();
        for (Mod mod : SPGlobal.getDB()) {
            importedMods.add(new ModBridge(mod));
        }
        return importedMods;
    }

    public JSkyMod findMod(String modName) {
        for (JSkyMod mod : getAllMods()) {
            if (mod.getName().equals(modName)) {
                return mod;
            }
        }
        return null;
    }
}
